package com.burst.reptile.framework.web.entity;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

import com.burst.reptile.modular.system.entity.SysDept;
import com.burst.reptile.modular.system.entity.SysMenu;
import com.burst.reptile.modular.zp.entity.ZpCity;
import com.fasterxml.jackson.annotation.JsonInclude;

import lombok.Data;

/**
 * Treeselect树结构实体类
 * @author wujin
 * @date: 2020年5月24日 下午2:21:00
 */
@Data
public class LayuiTreeSelect implements Serializable {
	
	private static final long serialVersionUID = 1L;

	/**
	 * 节点ID
	 */
	private String id;
	
	/**
	 * 父节点
	 */
	private String pid;
	
	/**
	 * 节点是否初始为选中状态
	 */
	private boolean checked;

	/**
	 * 节点名称
	 */
	private String title;
	
	/**
	 * 节点是否初始展开，默认 false
	 */
	private boolean spread;
	
	/**
	 * 子节点
	 */
	@JsonInclude(JsonInclude.Include.NON_EMPTY)
	private List<LayuiTreeSelect> children;

	public LayuiTreeSelect() {

	}
	
	public LayuiTreeSelect(SysDept dept) {
        this.id = String.valueOf(dept.getDeptId());
        this.title = dept.getDeptName();
        this.spread = true;
        this.pid = String.valueOf(dept.getParentId());
        this.children = dept.getChildren().stream().map(LayuiTreeSelect::new).collect(Collectors.toList());
    }

	public LayuiTreeSelect(SysMenu menu) {
		this.id = menu.getMenuId().toString();
		this.title = menu.getMenuName();
		this.pid = String.valueOf(menu.getParentId());
		this.children = menu.getChildren().stream().map(LayuiTreeSelect::new).collect(Collectors.toList());
	}

	public LayuiTreeSelect(ZpCity city) {
		this.id = city.getAid();
		this.title = city.getName();
		this.pid = city.getParentId();
		this.children = city.getChildren().stream().map(LayuiTreeSelect::new).collect(Collectors.toList());
	}
}
